package com.tsmti.lab.controller.system;

import com.tsmti.core.common.controller.BaseCrudController;
import com.tsmti.core.util.SpringContextUtils;
import com.tsmti.shiro.annotation.RequiresPathPermission;
import com.tsmti.system.entity.MessageProperty;
import com.tsmti.system.service.MessagePropertyService;
import com.tsmti.util.MessageResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Package：com.tsmti.lab.controller.system
 * @Class：MessagePropertyController
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/5/30 17:14
 * @Company:
 * @Version：
 * @Modified By:
 */
@Controller
@RequestMapping("/system/label")
@RequiresPathPermission("sys:label")
public class MessagePropertyController extends BaseCrudController<MessageProperty,Long> {
    @Autowired
    private MessagePropertyService messagePropertyService;
    /**
     * 判断该标签是否重复
     * @param messageProperty
     */
    @Override
    public boolean isRepeat(MessageProperty messageProperty) {
        if(messageProperty != null){
            List list  = messagePropertyService.getExistList(messageProperty);
            if(list != null && list.size() > 0){
                return true;
            }
        }
        System.out.println(111);
        return false;
    }

    @Override
    public void afterSave(MessageProperty messageProperty, HttpServletRequest request, HttpServletResponse response) {
        //修改后更新国际化缓存
        MessageResource messageSource = SpringContextUtils.getBean(MessageResource.class);
        messageSource.reload();
    }

}
